home *** CD-ROM | disk | FTP | other *** search
/ Whiteline: Alpha / Whiteline Alpha.iso / tex / tools / dvi / epson_90.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-22  |  5.9 KB  |  261 lines

  1. /*************************************************************************
  2. **** Querdruck für EPSON ESC/P 9-Nadeldrucker                         ****
  3. *************************************************************************/
  4.  
  5. #include <string.h>
  6.  
  7. #include <portab.h>
  8.  
  9. #include "mintbind.h"
  10. #include "treiber.h"
  11.  
  12. /** Vorläufige Parameter */
  13. #define MAX_DPI    240L
  14. #define    HOEHE    1920L
  15. #define WEITE -1L
  16. #define BITS_PER_CHAR    20    /* Elite-Dichte! */
  17. #define COMPRESSION 2    /* Von 2 bis 0 (so lassen) */
  18.  
  19. #ifdef FAST_PRN
  20. #define WRITE(i,j) ((th>0)?(Fwrite(th,i,j)):(print_block(i,j)))
  21. #endif
  22.  
  23.  
  24. /* Reset + NLQ + Einheit 1/MAX_DPI" + Zeilenabstand 1/216" */
  25. UBYTE    *INIT = "\033@\033M\033\063\001\015";
  26. UBYTE    *V_STEP    =    "\033f\001x";
  27. UBYTE    *H_STEP = "\033lx";
  28.  
  29.  
  30.  
  31.  
  32. void write_compressed( WORD th, UBYTE *tmp, LONG len, long bpc )
  33. {
  34. #if COMPRESSION==2
  35. /* Schneidet nur links und rechts ab */
  36. /* Diese Routine sollte mit nahezu jedem Drucker gehen! */
  37. /* wenn man BITS_PER_CHAR (bpc) kennt! */
  38.     LONG    i, j;
  39.  
  40.     for(  i=0;  i<len  &&  tmp[5+i]==0;  i++  )
  41.         ;
  42.     while(  tmp[len+4]==0  &&  len>i  )
  43.         len--;
  44.     if(  i==len  )
  45.         WRITE( 2L, "\015\012" );
  46.     else
  47.     {
  48.         for(  j=0;  j<i/bpc;  j++  )
  49.             WRITE( 1L, " " );
  50.         j *= bpc;
  51.         len -= j;
  52.         tmp[3] = (UBYTE)(len % 256);
  53.         tmp[4] = (UBYTE)(len / 256);
  54.         WRITE( 5L, tmp );
  55.         WRITE( len, tmp+5+j );
  56.         WRITE( 2L, "\015\012" );
  57.     }
  58. #elif COMPRESSION==1
  59.     LONG    i;
  60.  
  61. /* Schneidet nur rechts ab */
  62.     for(  i=len;  i>0  && tmp[i+5]==0;  i--  )
  63.         ;
  64.     len--;
  65.     if(  i==0  )
  66.         WRITE( 2L, "\015\012" );
  67.     else
  68.     {
  69.         len = i;
  70.         tmp[3] = (UBYTE)(len % 256);
  71.         tmp[4] = (UBYTE)(len / 256);
  72.         WRITE( 5L+len, tmp );
  73.         WRITE( 2L, "\015\012" );
  74.     }
  75. #else
  76.     WRITE( 7L+len, tmp );
  77. #endif
  78. }
  79. /* 23.8.93 */
  80.  
  81.  
  82. /* Zwischenspeicher für eine Zeile */
  83. static UBYTE    tmp1[HOEHE+6L];
  84. static UBYTE    tmp2[HOEHE+6L];
  85. static UBYTE    tmp3[HOEHE+6L];
  86.  
  87. static LONG    bit_table[]=
  88. {
  89.     0x00800000L,0x00400000L,0x00200000L,0x00100000L,
  90.     0x00080000L,0x00040000L,0x00020000L,0x00010000L,
  91.     0x00008000L,0x00004000L,0x00002000L,0x00001000L,
  92.     0x00000800L,0x00000400L,0x00000200L,0x00000100L,
  93.     0x00000080L,0x00000040L,0x00000020L,0x00000010L,
  94.     0x00000008L,0x00000004L,0x00000002L,0x00000001L
  95. };
  96.  
  97.  
  98.  
  99. WORD    drucke( UBYTE *p, LONG weite, LONG hoehe, LONG h_dpi, LONG v_dpi )
  100. {
  101.     extern char    tmp_file[256]; /* In Datei drucken? */
  102.  
  103.     LONG    max_spalte, max_zeile, zeile, lz;
  104.     LONG    len, bytes_per_row, offset, i, j, k;
  105.     WORD    th=0;
  106.     UBYTE    t;
  107.  
  108. #ifdef FAST_PRN
  109.     /* Für viel Geschwindigkeit */
  110.     if(  tmp_file[0]>0  ||  open_printer()<0  )
  111. #endif
  112.         th = (WORD)get_tempfile( "n9q" );
  113.     if(  th<0  )
  114.         return -1;
  115.  
  116.     t = '3';
  117.     j = 240;
  118.     if(  v_dpi<150  )
  119.     {
  120.         t = '1';
  121.         j = 120;
  122.     }
  123.  
  124.     v_dpi = 216;
  125.     bytes_per_row = 3;
  126.     if(  h_dpi<80  )
  127.     {
  128.         v_dpi = 72;
  129.         bytes_per_row = 1;
  130.     }
  131.     else
  132.         if(  h_dpi<160  )
  133.         {
  134.             v_dpi = 144;
  135.             bytes_per_row = 2;
  136.         }
  137.     h_dpi = j;
  138.  
  139.         /* Ab hier wird es ernst */
  140.     if(  hoehe>(HOEHE*h_dpi)/MAX_DPI  )
  141.         max_spalte = (HOEHE*h_dpi)/MAX_DPI;
  142.  
  143.         /* Diverse Variablen initialisieren */
  144.     zeile = 0;
  145.     if(  WEITE>0    &&    (weite*v_dpi)/MAX_DPI>WEITE  )
  146.         max_zeile = (WEITE+7)*v_dpi/(8*MAX_DPI);
  147.     else
  148.         max_zeile = (weite+7L)/8L;
  149.     weite = (weite+15L)/16L;
  150.     weite *= 2;
  151.  
  152.         /* Reset + LQ-Mode */
  153.     WRITE( 8L, INIT );
  154.  
  155.     /* Endlich drucken */
  156.     max_zeile--;
  157.     while(    zeile<max_zeile )
  158.     {
  159.         for(  lz=0;  ist_next_leer( p+lz, weite, hoehe )  &&  lz<max_zeile;  lz++  )
  160.             ;
  161.         if(     lz>0    )
  162.         {    /* Leerzeilen überspringen */
  163.             zeile += lz;
  164.             p += lz;
  165.             lz = lz*8*3/bytes_per_row;
  166.              while(  lz>0  )
  167.             {
  168.                 if(  lz>255  )
  169.                     V_STEP[3] = 255;
  170.                 else
  171.                     V_STEP[3] = lz;
  172.                 WRITE( 4L, V_STEP );
  173.                 lz -= 255;
  174.             }
  175.         }
  176.         if(  zeile>=max_zeile  )
  177.             break;
  178.  
  179.         len = max_spalte;
  180.         if(  max_spalte<(HOEHE*h_dpi)/MAX_DPI  )
  181.             offset = (HOEHE*h_dpi)/MAX_DPI-max_spalte;
  182.         else
  183.             offset = 0;
  184.         tmp1[0] = '\033';
  185.         tmp1[1] = '*';
  186.         tmp1[2] = t;
  187.  
  188.         switch(  (int)bytes_per_row  )
  189.         {
  190.             case 1:    for(  lz=0;  lz<len;  lz++  )
  191.                                 tmp1[4L+offset+len-lz] = p[lz*weite];
  192.                             memset( tmp1+5, 0, offset );
  193.                             tmp1[3] = (UBYTE)((len+offset) % 256);
  194.                             tmp1[4] = (UBYTE)((len+offset) / 256);
  195.                             write_compressed( th, tmp1, len+offset, (BITS_PER_CHAR*h_dpi)/MAX_DPI );
  196.                             p += 1;
  197.                         break;
  198.             case 2:    memset(  tmp1+5, 0, offset+len );
  199.                             memcpy(  tmp2, tmp1, 5+offset+len );
  200.                             for(  lz=0;  lz<len;  lz++  )
  201.                             {
  202.                                 i = 256L*p[lz*weite]+p[lz*weite+1];
  203.                                 if(  i==0L  )
  204.                                     continue;
  205.                                 for(  j=8,k=0;  k<8;  k++  )
  206.                                 {
  207.                                     if(  (i&bit_table[j++])!=0L  )
  208.                                         tmp1[4L+offset+len-lz] |= bit_table[16+k];
  209.                                     if(  (i&bit_table[j++])!=0L  )
  210.                                         tmp2[4L+offset+len-lz] |= bit_table[16+k];
  211.                                 }
  212.                             }
  213.                             /* Komprimiert schreiben */
  214.                             write_compressed( th, tmp1, len+offset, (BITS_PER_CHAR*h_dpi)/MAX_DPI );
  215.                             write_compressed( th, tmp2, len+offset, (BITS_PER_CHAR*h_dpi)/MAX_DPI );
  216.                             p += 2;
  217.                         break;
  218.             case 3:    memset(  tmp1+5, 0, offset+len );
  219.                             memcpy(  tmp2, tmp1, 5+offset+len );
  220.                             memcpy(  tmp3, tmp1, 5+offset+len );
  221.                             for(  lz=0;  lz<len;  lz++  )
  222.                             {
  223.                                 i = p[lz*weite]*65536L+p[lz*weite+1]*256L+p[lz*weite+2];
  224.                                 if(  i==0  )
  225.                                     continue;
  226.                                 for(  j=k=0;  k<8;  k++  )
  227.                                 {
  228.                                     if(  (i&bit_table[j++])!=0  )
  229.                                         tmp1[4L+offset+len-lz] |= bit_table[16+k];
  230.                                     if(  (i&bit_table[j++])!=0  )
  231.                                         tmp2[4L+offset+len-lz] |= bit_table[16+k];
  232.                                     if(  (i&bit_table[j++])!=0  )
  233.                                         tmp3[4L+offset+len-lz] |= bit_table[16+k];
  234.                                 }
  235.                             }
  236.                             write_compressed( th, tmp1, len+offset, (BITS_PER_CHAR*h_dpi)/MAX_DPI );
  237.                             write_compressed( th, tmp2, len+offset, (BITS_PER_CHAR*h_dpi)/MAX_DPI );
  238.                             write_compressed( th, tmp3, len+offset, (BITS_PER_CHAR*h_dpi)/MAX_DPI );
  239.                             p += 3;
  240.                         break;
  241.         }
  242.         V_STEP[3] = 24-bytes_per_row;
  243.         WRITE( 4L, V_STEP );
  244.         zeile += bytes_per_row;
  245.     }
  246.  
  247.         /* Ende Seite */
  248.     if(  2!=WRITE( 1L, " \014" )  )
  249.     {
  250.         /* Platz reichte nicht aus */
  251.         if(  th>0  )
  252.             Fclose( th );
  253.         th = -1;
  254.     }
  255.  
  256.     if(  tmp_file[0]==0  )
  257.         flush_block();
  258.     return th;
  259. }
  260. /* 17.1.93 */
  261.